package GUI;

import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JButton;

import net.sourceforge.jdatepicker.impl.JDatePanelImpl;
import net.sourceforge.jdatepicker.impl.JDatePickerImpl;
import net.sourceforge.jdatepicker.impl.SqlDateModel;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class EditEvent extends JPanel {

	
	private static final long serialVersionUID = 1L;
	private JTextField placeTextField;
	private JTextField priceTextField;
	private JButton btnBack;
	private JButton btnChange;
	private JCheckBox chckbxNewPrice;
	private JCheckBox chckbxNewPlace;
	private JCheckBox chckbxNewDate;
	private JCheckBox chckbxPaied;
	private JLabel iconlabel;
	private JCheckBox chckbxNewTime;
	private JTextField NewTimetextField;
	private JDatePickerImpl edatePicker;
	
	/**
	 * Constructor
	 */
	public EditEvent() {
		setLayout(null);
		
		chckbxNewDate = new JCheckBox("new date");
		chckbxNewPlace = new JCheckBox("new place");
		placeTextField = new JTextField();
		chckbxNewPrice = new JCheckBox("new price");
		priceTextField = new JTextField();
		priceTextField.addKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent evt) {
				char c = evt.getKeyChar();
				if(!(Character.isDigit(c) || (c==KeyEvent.VK_BACK_SPACE) || (c==KeyEvent.VK_DELETE))){
					getToolkit().beep();
					evt.consume();
				}
			}
		});
		btnChange = new JButton("Change");
		btnChange.setIcon(new ImageIcon(EditEvent.class.getResource("/resources/change.png")));
		btnBack = new JButton("Back");
		btnBack.setIcon(new ImageIcon(EditEvent.class.getResource("/resources/back22.png")));
		chckbxPaied = new JCheckBox("paied");
		chckbxNewTime = new JCheckBox("New Time");
		NewTimetextField = new JTextField();
		
		
		initialize();
	}

	private void initialize() {
			
		btnChange.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		chckbxNewDate.setFont(new Font("Tahoma", Font.BOLD, 12));
		chckbxNewPlace.setFont(new Font("Tahoma", Font.BOLD, 12));
		chckbxNewPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		JLabel lblEditEvent = new JLabel("Edit Event");
		lblEditEvent.setForeground(new Color(0, 204, 255));
		lblEditEvent.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblEditEvent.setBounds(10, 24, 97, 19);
		add(lblEditEvent);
		
		chckbxNewDate.setBounds(250, 108, 101, 27);
		add(chckbxNewDate); 
		
		SqlDateModel model1 = new SqlDateModel();
		JDatePanelImpl datePanel1 = new JDatePanelImpl(model1);
		edatePicker = new JDatePickerImpl(datePanel1);
		edatePicker.setBounds(408, 109, 101, 27);
		edatePicker.setEnabled(false);
		add(edatePicker);
	
		chckbxNewPlace.setBounds(250, 172, 101, 27);
		add(chckbxNewPlace); 
		
		placeTextField.setBounds(408, 173, 101, 27);
		placeTextField.setEnabled(false);
		add(placeTextField);
		placeTextField.setColumns(10);
		
		chckbxNewPrice.setBounds(250, 241, 101, 27);
		add(chckbxNewPrice);
		
		priceTextField.setBounds(408, 242, 101, 27);
		priceTextField.setEnabled(false);
		add(priceTextField);
		priceTextField.setColumns(10);
		
		btnChange.setBounds(353, 435, 121, 27);
		add(btnChange);
		
		btnBack.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		btnBack.setBounds(10, 462, 101, 27);
		add(btnBack);
		
		
		chckbxPaied.setFont(new Font("Tahoma", Font.BOLD, 12));
		chckbxPaied.setBounds(250, 379, 101, 27);
		add(chckbxPaied);
		
		ImageIcon LOGOImageIcon = new ImageIcon(getClass().getClassLoader().getResource("resources/camera-background3.png"));
		ImageIcon LOGO = new ImageIcon (LOGOImageIcon.getImage().getScaledInstance(-1, -1, java.awt.Image.SCALE_SMOOTH));
		
		
		chckbxNewTime.setFont(new Font("Tahoma", Font.BOLD, 12));
		chckbxNewTime.setBounds(250, 306, 101, 27);
		add(chckbxNewTime);
		
		
		NewTimetextField.setBounds(408, 307, 101, 27);
		NewTimetextField.setEnabled(false);
		add(NewTimetextField);
		NewTimetextField.setColumns(10);
		
		chckbxNewTime.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(chckbxNewTime.isSelected())
					NewTimetextField.setEnabled(true);
				else
					NewTimetextField.setEnabled(false);
			}
		});
		
		chckbxNewDate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(chckbxNewDate.isSelected())
					edatePicker.setEnabled(true);
				else
					edatePicker.setEnabled(false);
			}
		});
		
		chckbxNewPlace.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(chckbxNewPlace.isSelected())
					placeTextField.setEnabled(true);
				else
					placeTextField.setEnabled(false);
			}
		});
		
		
		chckbxNewPrice.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(chckbxNewPrice.isSelected())
					priceTextField.setEnabled(true);
				else
					priceTextField.setEnabled(false);
			}
		});
		
		
		iconlabel = new JLabel("");
		iconlabel.setIcon(LOGO);
		iconlabel.setBounds(0, 0, 786, 500);
		add(iconlabel);
		}

	/**
	 * @return the placeTextField
	 */
	public JTextField getPlaceTextField() {
		return placeTextField;
	}

	/**
	 * @param placeTextField the placeTextField to set
	 */
	public void setPlaceTextField(JTextField placeTextField) {
		this.placeTextField = placeTextField;
	}

	/**
	 * @return the priceTextField
	 */
	public JTextField getPriceTextField() {
		return priceTextField;
	}

	/**
	 * @param priceTextField the priceTextField to set
	 */
	public void setPriceTextField(JTextField priceTextField) {
		this.priceTextField = priceTextField;
	}

	/**
	 * @return the btnBack
	 */
	public JButton getBtnBack() {
		return btnBack;
	}

	/**
	 * @return the btnChange
	 */
	public JButton getBtnChange() {
		return btnChange;
	}

	/**
	 * @return the chckbxNewPrice
	 */
	public JCheckBox getChckbxNewPrice() {
		return chckbxNewPrice;
	}

	/**
	 * @return the chckbxNewPlace
	 */
	public JCheckBox getChckbxNewPlace() {
		return chckbxNewPlace;
	}

	/**
	 * @return the chckbxNewDate
	 */
	public JCheckBox getChckbxNewDate() {
		return chckbxNewDate;
	}

	/**
	 * @return the chckbxPaied
	 */
	public JCheckBox getChckbxPaied() {
		return chckbxPaied;
	}


	/**
	 * @return the chckbxNewTime
	 */
	public JCheckBox getChckbxNewTime() {
		return chckbxNewTime;
	}

	/**
	 * @param chckbxNewTime the chckbxNewTime to set
	 */
	public void setChckbxNewTime(JCheckBox chckbxNewTime) {
		this.chckbxNewTime = chckbxNewTime;
	}

	/**
	 * @return the newTimetextField
	 */
	public JTextField getNewTimetextField() {
		return NewTimetextField;
	}

	/**
	 * @param newTimetextField the newTimetextField to set
	 */
	public void setNewTimetextField(JTextField newTimetextField) {
		NewTimetextField = newTimetextField;
	}

	/**
	 * @param btnBack the btnBack to set
	 */
	public void setBtnBack(JButton btnBack) {
		this.btnBack = btnBack;
	}

	/**
	 * @param btnChange the btnChange to set
	 */
	public void setBtnChange(JButton btnChange) {
		this.btnChange = btnChange;
	}

	/**
	 * @param chckbxNewPrice the chckbxNewPrice to set
	 */
	public void setChckbxNewPrice(JCheckBox chckbxNewPrice) {
		this.chckbxNewPrice = chckbxNewPrice;
	}

	/**
	 * @param chckbxNewPlace the chckbxNewPlace to set
	 */
	public void setChckbxNewPlace(JCheckBox chckbxNewPlace) {
		this.chckbxNewPlace = chckbxNewPlace;
	}

	/**
	 * @param chckbxNewDate the chckbxNewDate to set
	 */
	public void setChckbxNewDate(JCheckBox chckbxNewDate) {
		this.chckbxNewDate = chckbxNewDate;
	}

	/**
	 * @param chckbxPaied the chckbxPaied to set
	 */
	public void setChckbxPaied(JCheckBox chckbxPaied) {
		this.chckbxPaied = chckbxPaied;
	}

	/**
	 * @return the event date in SQL format
	 */
	public String getEdatePicker()
	{
		java.sql.Date selectedDate = (java.sql.Date)edatePicker.getModel().getValue();
		if(selectedDate == null) return "";
		return selectedDate.toString();
	}
}
